package com.iris.temp;

public class NumAddUtil {

    public static String numAdd(String numA,String numB){
        String str="";
        int lenA=numA.length();
        int lenB=numB.length();
        //给短的字符串补齐的数字0
        String preStr="";
        //要补齐0的字符串个数
        int minusCount = 0;

        if(lenA>lenB){
            minusCount = lenA-lenB;
            preStr = buildPreStr(minusCount);
            //补齐长度
            numB = preStr+numB;
        }else if(lenB>lenA){
            minusCount = lenB-lenA;
            preStr = buildPreStr(minusCount);
            //补齐长度
            numA = preStr+numA;
        }

        System.out.println(numA);
        System.out.println(numB);
        StringBuilder sb = new StringBuilder();
        int charA,charB,result;
        //十进一标志位
        int addFlag=0;
        for(int i=numA.length()-1;i>=0;i--){
            charA=Integer.valueOf(numA.charAt(i)+"");
            charB=Integer.valueOf(numB.charAt(i)+"");
            result=charA+charB+addFlag;
            addFlag=result/10;
            result=result%10;
            sb.append(result);
        }
        if(addFlag==1){
            sb.append(1);
        }
        str=sb.reverse().toString();
        return str;
    }

    public static String buildPreStr(int count){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < count; i++) {
            sb.append("0");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String str = NumAddUtil.numAdd("11777779823123","823123");
        System.out.println(str);
        int[] a = new int[]{1,3,44,5,446,56,78,90,666};
        NumAddUtil.maxMin(a);
    }

    public static void maxMin(int[] A)
    {
        int i;
        int n=A.length;
        int max=0;
        int min=0;
        if(n%2==0)
        {
            if(A[0]>A[1])
            {
                max=A[0];
                min=A[1];
            }
            else
            {
                max=A[1];
                min=A[0];
            }
            for(i=2;i<n-1;i=i+2)
            {
                if(A[i]>A[i+1])
                {
                    if(max<A[i])
                        max=A[i];
                    if(min>A[i+1])
                        min=A[i+1];
                }
                else
                {
                    if(max<A[i+1])
                        max=A[i+1];
                    if(min>A[i])
                        min=A[i];
                }
            }
        }
        else
        {
            max=min=A[0];
            for(i=1;i<n-1;i=i+2)
            {
                if(A[i]>A[i+1])
                {
                    if(max<A[i])
                        max=A[i];
                    if(min>A[i+1])
                        min=A[i+1];
                }
                else
                {

                    if(max<A[i+1])
                        max=A[i+1];
                    if(min>A[i])
                        min=A[i];
                }
            }
        }
        System.out.println(max);
        System.out.println(min);
    }


}
